package com.ldl.origami.origamiService;

import com.ldl.origami.dao.CategoryMapper;
import com.ldl.origami.domain.Category;
import com.ldl.origami.domain.CategoryExample;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能描述:
 * 作者: LDL
 * 创建时间: 2014/9/2 10:49
 */
@Service
public class CategoryService {

    static org.slf4j.Logger logger = LoggerFactory.getLogger(CategoryService.class);
    @Autowired(required = false)
    private CategoryMapper categoryMapper;


    /**
     * 获取所有类别
     * @return
     */
    public List<Category> getCategories(){
        CategoryExample example = new CategoryExample();
        return categoryMapper.selectByExample(example);
    }

    /**
     * 根据Id获取类别
     * @param categoryId
     * @return
     */
    public Category getCategoryById(int categoryId) throws Exception {

        Category category = null;
        try {
            category = categoryMapper.selectByPrimaryKey(categoryId);
        } catch (Exception e) {
            throw new Exception();
        }
        return category;
    }
}
